Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: BaseModel abstract class, primitive Style Transfer, functions for retrieving model metadata #44

Merged
merged 27 commits into from
Dec 9, 2024

Conversation

NorbertKlockiewicz
Copy link
Contributor

@NorbertKlockiewicz NorbertKlockiewicz commented Dec 5, 2024

Description

This pull request introduces Model base class on top of which every other model should be built, there's also a primitive implementation of StyleTransferModel and functions for retrieving model metadata. Fix for bindings allowing to return multiple outputs.

During code review don't focus on StyleTransfer Module as it will change and it's for test purposes right now

Don't review:

  • StyleTransfer.kt
  • StyleTransferModel.kt
  • StyleTransfer.h
  • StyleTransfer.mm
  • StyleTransferModel.mm
  • StyleTransferModel.h
  • BitmapUtils.kt
  • Imageprocessor.h/Imageprocessor.m
  • TensorUtils.kt

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (improves or adds clarity to existing documentation)

Tested on

  • iOS
  • Android

Testing instructions

Screenshots

Related issues

Checklist

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly
  • My changes generate no new warnings

Additional notes

@NorbertKlockiewicz NorbertKlockiewicz marked this pull request as draft December 5, 2024 15:32
@NorbertKlockiewicz NorbertKlockiewicz changed the title @norbertklockiewicz/style transfer feat: BaseModel abstract class, primitive Style Transfer, functions for retrieving model metadata Dec 5, 2024
@NorbertKlockiewicz NorbertKlockiewicz marked this pull request as ready for review December 5, 2024 16:46
android/build.gradle Outdated Show resolved Hide resolved
android/libs/executorch-llama.aar Outdated Show resolved Hide resolved
return @(method_meta->num_outputs());
}

return @-1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Comment on lines 16 to 29
private fun downloadModel(
url: String, callback: (path: String?, error: Exception?) -> Unit
) {
Fetcher.downloadResource(context,
client,
url,
ResourceType.MODEL,
false,
{ path, error -> callback(path, error) },
object : ProgressResponseBody.ProgressListener {
override fun onProgress(bytesRead: Long, contentLength: Long, done: Boolean) {
}
})
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move the callback inside the downloadModel method, as it is right now is a bit convoluted for no apparent reason (unless there is one I'm missing)

throw Error("18")
} catch (e: Exception) {
//Executorch forward method throws an exception with a message: "Method forward failed with code XX"
val exceptionCode = e.message!!.substring(e.message!!.length - 2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this a bit of a hurdle to maintain, what if the error format from ET changes? Let's check if the message matches a regex first or match it against the pattern typed out in the comment, if it doesn't let's then return the whole error message unchanged

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are controlling what error message is thrown from executorch, I will modify it to return only code so we overcome overhead with processing whole message

@interface BaseModel : NSObject
{
@protected
ETModel *module;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought, shouldn't this be model? module seems confusing since we have ETModule which is an abstraction over the ETModel?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about it but that's how it was called in ETModel.mm so I wanted to keep it the same here

ios/RnExecutorch/models/ImageProcessor.h Outdated Show resolved Hide resolved
src/StyleTransfer.ts Outdated Show resolved Hide resolved
src/StyleTransfer.ts Show resolved Hide resolved
NorbertKlockiewicz and others added 10 commits December 8, 2024 13:47
This PR fixes the issue in iOS ExecuTorch bindings where if the model
returned multiple output arrays, only the first one was considered.

## Description
<!-- Provide a concise and descriptive summary of the changes
implemented in this PR. -->

### Type of change
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Documentation update (improves or adds clarity to existing
documentation)

### Tested on
- [x] iOS
- [ ] Android

### Testing instructions
<!-- Provide step-by-step instructions on how to test your changes.
Include setup details if necessary. -->

### Screenshots
<!-- Add screenshots here, if applicable -->

### Related issues
<!-- Link related issues here using #issue-number -->

### Checklist
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have updated the documentation accordingly
- [ ] My changes generate no new warnings

### Additional notes
<!-- Include any additional information, assumptions, or context that
reviewers might need to understand this PR. -->
@NorbertKlockiewicz NorbertKlockiewicz merged commit e96d46f into main Dec 9, 2024
3 checks passed
@NorbertKlockiewicz NorbertKlockiewicz deleted the @norbertklockiewicz/style-transfer branch December 9, 2024 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants